/// 设备状态枚举
enum DeviceStatus {
  /// 在线状态
  online,
  
  /// 离线状态
  offline,
  
  /// 故障状态
  fault,
  
  /// 禁用状态
  disabled,
  
  /// 维护状态
  maintenance,
  
  /// 休眠状态
  sleep,
  
  /// 未激活状态
  inactive,
  
  /// 未知状态
  unknown,
}

/// 设备状态扩展
extension DeviceStatusExtension on DeviceStatus {
  /// 将字符串转换为设备状态
  static DeviceStatus fromString(String value) {
    return DeviceStatus.values.firstWhere(
      (status) => status.toString().split('.').last.toLowerCase() == value.toLowerCase(),
      orElse: () => DeviceStatus.unknown,
    );
  }

  /// 获取设备状态的显示名称
  String get displayName {
    switch (this) {
      case DeviceStatus.online: return '在线';
      case DeviceStatus.offline: return '离线';
      case DeviceStatus.fault: return '故障';
      case DeviceStatus.disabled: return '已禁用';
      case DeviceStatus.maintenance: return '维护中';
      case DeviceStatus.sleep: return '休眠';
      case DeviceStatus.inactive: return '未激活';
      case DeviceStatus.unknown: return '未知';
    }
  }

  /// 获取设备状态的颜色代码
  String get colorCode {
    switch (this) {
      case DeviceStatus.online: return '#4CAF50'; // 绿色
      case DeviceStatus.offline: return '#9E9E9E'; // 灰色
      case DeviceStatus.fault: return '#F44336'; // 红色
      case DeviceStatus.disabled: return '#607D8B'; // 蓝灰色
      case DeviceStatus.maintenance: return '#FF9800'; // 橙色
      case DeviceStatus.sleep: return '#2196F3'; // 蓝色
      case DeviceStatus.inactive: return '#9C27B0'; // 紫色
      case DeviceStatus.unknown: return '#000000'; // 黑色
    }
  }
  
  /// 判断设备是否可用
  bool get isAvailable {
    return this == DeviceStatus.online;
  }
  
  /// 判断设备是否有故障
  bool get isFault {
    return this == DeviceStatus.fault;
  }
  
  /// 判断设备是否离线
  bool get isOffline {
    return this == DeviceStatus.offline;
  }
} 